<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>岗位管理</title>
<script src="${ctx}/static/selectWin/postSelector.js?version=${applicationScope.jsVersion }" type="text/javascript">
	
</script>
<script type="text/javascript">
	var $tree;
	var $grid;
	var selectTableRow;//选中的行数据
	$(function() {

		$tree = $("#tree").tree({
			method : "get",
			lines : true,
			url : "${ctx}/basic/organization/tree/",
			dataPlain : true, //该属性用以启用当前 easyui-tree 控件对平滑数据格式的支持
			toggleOnClick : true,
			onSelect : function(node) {
				selectTableRow = node;
				$("#cc").layout("panel", "east").panel({
					title : "【" + node.text + "】岗位明细管理"
				});
				$("#search_EQ_orgId").val(node.id);
				$grid.datagrid({
					url : "${ctx}/basic/post/dataGrid/" + node.id
				});
				search_line();
				$("#orgId").combobox({
					valueField : 'id',
					textField : 'orgName',
					method : 'get',
					url : "${ctx}/basic/post/orgList/" + node.id,
					disabled : "disabled"
				});
			}
		});
		$grid = $("#grid").datagrid($.extend(datagridOption, {
			fitColumns : true,
			url : "",
			columns : [ [ {
				field : 'id',
				checkbox : true
			}, {
				field : 'postNo',
				title : '岗位编码',
				width : 40,
				sortable : true
			}, {
				field : 'postName',
				title : '岗位名称',
				width : 60,
				sortable : true
			}, {
				field : 'description',
				title : '描述',
				width : 60,
				sortable : true
			}, {
				field : 'enable',
				title : '是否启用',
				width : 60,
				sortable : true,
				formatter : function(value, row, index) {
					return '<input class="easyui-switchbutton "' + (value == 1 ? "checked" : "") 
					+ ' data-options="readonly:true,onText:\'是\',offText:\'否\'">';
				}
			}, {
				field : 'higherPost',
				title : '上级岗位',
				width : 60,
				sortable : true,
				formatter : function(value) {
					if (value == null) {
						return '<span style="color:blue">暂无上级岗位</span>';
					} else {
						return value.postName;
					}
				}
			} ] ]
		}));
		$("#enableSB").switchbutton({
			onText : "是",
			offText : "否",
			checked : true,
			onChange : function(checked) {
				if (checked) {
					$("#enable").val(1);
				} else {
					$("#enable").val(2);
				}
			}
		});
		search_line();
		$("#btn-add").click(function() {
			if (!selectTableRow) {
				$.messager.show({
					icon : "error",
					msg : "请先选中对应的组织机构"
				});
				return false;
			}
			$("#dlg").dialog("open").dialog("setTitle", "新增岗位");
			$("#fm").form("clear").form("load", {
				description : '请在这里输入职位描述',
				enable : 1
			});
			$("#enableSB").switchbutton('check');
			$("#orgId").combobox("select", $("#search_EQ_orgId").val());
			
			//$("#radio1").attr("checked", "checked");
			$("#higherPost").comboselector(postSelectOpts).comboselector({
				url : "${ctx}/basic/post/showInfo/" + $("#search_EQ_orgId").val()
			});
		});
		$("#btn-edit").click(function() {
			var row = $("#grid").datagrid("getSelected");
			if (row == null) {
				showAlert("您未选择任何记录!");
			} else {
				$("#dlg").dialog("open").dialog("setTitle", "编辑岗位--[" + row.postName + "]");
				$("#fm").form("clear").form("load", row);
				$("#enableSB").switchbutton(rowData.enable == 1 ? "check" : "uncheck");
				$("#orgId").combobox("select", $("#search_EQ_orgId").val());
				$("#higherPost").comboselector(postSelectOpts).comboselector({
					url : "${ctx}/basic/post/showInfo/" + $("#search_EQ_orgId").val()
				});
				if (row.higherPost != null) {
					$("#higherPost").comboselector(postSelectOpts).comboselector({
						url : "${ctx}/basic/post/showInfo/" + $("#search_EQ_orgId").val()
					});
					$("#higherPost").comboselector("setValue", row.higherPost.id).comboselector("setText", row.higherPost.postName);
				}
			}
		});
		$("#btn-delete").click(function() {
			multiDeleteDataGrid($("#grid"), "${ctx}/basic/post/multiDelete");
		});
		$("#excelExport").click(
				function() {
					var url = "${ctx}/basic/post/excelExport?" + $.param($("#grid").datagrid('options').queryParams) + "&orgId="
							+ selectTableRow.id;
					if ($("#grid").datagrid("options").filterRules) {
						url += "&filterRules=" + JSON.stringify($("#grid").datagrid("options").filterRules);
					}
					window.parent.location.href = url;
				});
	});
	function fun_post_save() {
		var i = 0;
		if ($("#postNo").val() == null) {
			$.messager.show({
				msg : "您未输入岗位编号！",
				icon : "warning",
				position : "bottomRight"
			});
			i = 1;
		}
		if ($("#postName").val() == null) {
			$.messager.show({
				msg : "您未输入岗位名称！",
				icon : "warning",
				position : "bottomRight"
			});
			i = 1;
		}
		$("#fm").form("submit", {
			url : "${ctx}/basic/post/update?orgId="+ $("#search_EQ_orgId").val(),
			success : function(data) {
				if (data.success) {
					$("#dlg").dialog("close");
					$grid.datagrid({
						url : "${ctx}/basic/post/showInfo/" + $("#search_EQ_orgId").val()
					});
				}
				showInfo(data.msg);
			}
		});
	}
	function search_line() {
		var str = "-1";
		if ($("#search_EQ_orgId").val() != null) {
			str = $("#search_EQ_orgId").val();
		}
		$("#grid").datagrid('enableFilter', [ {
			field : 'higherPost',
			type : 'combobox',
			options : {
				valueField : 'id',
				textField : 'postName',
				panelHeight : 'auto',
				url : "${ctx}/basic/post/postList?orgId=" + str,
				onChange : function(value) {
					if (value == '') {
						$("#grid").datagrid('removeFilterRule', 'higherPost');
					} else {
						$("#grid").datagrid('addFilterRule', {
							field : 'higherPostId',
							op : 'EQ',
							value : value
						});
					}
					$("#grid").datagrid('doFilter');
				}
			}
		}, {
			field : 'enable',
			type : 'combobox',
			javaType : 'I',
			options : {
				panelHeight : 'auto',
				data : [ {
					value : '',
					text : '全部'
				}, {
					value : '1',
					text : '是'
				}, {
					value : '2',
					text : '否'
				} ],
				onChange : function(value) {
					if (value == '') {
						$("#grid").datagrid('removeFilterRule', 'enable');
					} else {
						$("#grid").datagrid('addFilterRule', {
							field : 'enable',
							op : 'EQ',
							value : value
						});
					}
					$("#grid").datagrid('doFilter');
				}
			}
		} ]);
	}
</script>
</head>

<body>
	<div data-options="region:'center',fit:true,border:false">
		<div id="cc" class="easyui-layout" data-options="fit:true" style="width: 680px; height: 440px;">
			<div data-options="region:'center',title:'组织架构'" style="padding: 1px; witdh: 300px">
				<ul id="tree">
				</ul>
			</div>
			<div id="dlg1" data-options="region:'east',split: true, collapsible:true,title : '岗位信息'" style="padding: 1px; witdh: 600px">
				<div id="tt" class="row">
				<div class="col-md-12">
					<!-- 查询条件 -->
					<!--  <form class="form-grid-search form-inline">
				<div class="form-group">
					<input type="text" class="form-control" name="search_EQ_orgId" placeholder="系统配置名称" />
				</div>
				<button type="button" id="search" class="btn btn-primary">
					<span class="glyphicon glyphicon-search"></span> 查询
				</button>
			</form>-->
					<input type="text" id="search_EQ_orgId"
						style="margin-left: 2px; margin-right: 2px; padding-left: 2px; padding-right: 3px; display: none;" />
					<!-- 功能按钮 -->
					<shiro:hasPermission name="post:update">
						<button id="btn-add" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-plus"></span> 新增岗位
				</button>
				<button id="btn-edit" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-pencil"></span> 编辑岗位信息
				</button>
					</shiro:hasPermission>
					<shiro:hasPermission name="post:delete">
						<button id="btn-delete" type="button" class="btn btn-danger">
					<span class="glyphicon glyphicon-minus"></span> 删除
				</button>
					</shiro:hasPermission>
					<shiro:hasPermission name="post:export">
						<button id="excelExport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-save"></span> Excel导出
				</button>
					</shiro:hasPermission>
					</div>
				</div>
				<table id="grid">
				</table>
				<shiro:hasPermission name="post:update">
					<div id="dlg" class="easyui-dialog" style="width: 610px; height: 400px; padding: 10px 20px" closed="true"
						data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
						<form id="fm" method="post">
							<input id="id" type="hidden" name="id" />
							<table id="tbl">
								<tr>
									<td><label>所属组织:</label></td>
									<td><input id="orgId" name="orgId" class="easyui-validatebox" /></td>
									<td><label>岗位编码:</label></td>
									<td><input id="postNo" name="postNo" class="easyui-validatebox" data-options="required:true" /></td>
								</tr>
								<tr>
									<td><label>岗位名称:</label></td>
									<td><input id="postName" name="postName" class="easyui-validatebox" data-options="required:true" /></td>
									<td><label>上级岗位:</label></td>
									<td><input id="higherPost" name="higherPostId" class="easyui-validatebox"></td>
								</tr>
								<tr>
									<td><label>启用:</label></td>
									<td><input type="hidden" id="enable" name="enable"/><input id="enableSB"/></td>
								</tr>
								<tr>
									<td><label>描述:</label></td>
									<td colspan="3"><input name="description" class="easyui-textbox"   data-options="multiline:true,width:449,height:60">
									</td>
								</tr>
							</table>
						</form>
						<div id="dlg-btn">
				<button id="add" type="button" class="btn btn-primary" onclick="fun_post_save();">
					<span class="glyphicon glyphicon-ok"></span> 保存
				</button>
				<button id="edit" type="button" class="btn btn-primary" onclick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
					</div>
				</shiro:hasPermission>
			</div>
		</div>
	</div>
</body>
</html>
